ISO8601Duration2Numbers
(9 actions, 8 KB)
0 Comment
https://en.m.wikipedia.org/wiki/ISO_8601#Durations
1 Text
➔ pattern
»
2
5
PT(?:([0-9]+)H)?(?:([0-9]+)M)?(?:([0-9]+)S)?
2 Match Text
[1 pattern]
in
[Shortcut Input]
»
MatchTextCaseSensitive
:
true
3 If
[2 Matches]
has any value
4 Dictionary »
{ "duration": "
[Shortcut Input]
" }
5 Text »
let dict =
[4 Dictionary]
const regex = new RegExp('
[1 pattern]
') const matches = regex.exec(dict.duration) const hours = parseInt(matches[1] || '0', 10) const minutes = parseInt(matches[2] || '0', 10) const seconds = parseInt(matches[3] || '0', 10) let durationInSeconds = (hours * 3600) + (minutes * 60) + seconds let durationInMinutes = Math.ceil((hours * 60) + minutes + (seconds / 60)) let out = { "durationInSeconds": durationInSeconds, "durationInMinutes": durationInMinutes } document.write(JSON.stringify(out))
6 Run Shortcut
Run JavaScript Code
»
Input
:
[5 Text]
Workflow
:
{ "workflowIdentifier": "E2CEB2A0-A1D2-4040-B3D2-804B9C84CAE8", "workflowName": "Run JavaScript Code", "isSelf": false }
7 Stop and Output
[6 Shortcut Result]
8 End If